<!-- vuex 中原生方法的使用 -->

<template>
    <div class="box">
        <h2>Son1 子组件</h2>
        从vuex中获取的值: <label>{{ $store.state.count }}</label>
        <br>
        <button @click="handleAdd(1)">值 + 1</button>
        <button @click="handleAdd(5)">值 + 5</button>
        <button @click="handleAdd(10)">值 + 10</button>
        <button @click="handleChange">一秒后修改成666</button>
        <button @click="changeFn">改标题</button>
        <hr>
        <div>{{ $store.state.list }}</div>
        <div>{{ $store.getters.filterList }}</div>
    </div>
</template>

<script>
export default {
    name: 'Son1Com',
    methods: {
        handleAdd(n) {
            console.log(n)
            // 调用带参数的 mutations 函数
            this.$store.commit('addCount', {
                count: n,
                msg: '哇哇哇'
            })
        },
        changeFn() {
            this.$store.commit('changeTitle', '哈哈哈')
        },
        handleChange() {
            this.$store.dispatch('changeCountAction', 666)
        }
    }
}
</script>

<style lang="css" scoped>
.box {
    border: 3px solid #ccc;
    width: 400px;
    padding: 10px;
    margin: 20px;
}

h2 {
    margin-top: 10px;
}
</style>
